 
threads.start(function(){
    xuanfu();
});
device.setMusicVolume(0)
device.setAlarmVolume(0)
device.setNotificationVolume(0)
toastLog("降低屏幕亮度")
device.keepScreenDim(30000)
// 调整屏幕亮度
device.setBrightness(60)
launchApp("微信");
wait("我")
console.log("进入微信")
sleep(1000)
点击不可点击文本("微信")
sleep(5000)
向下滑动()
sleep(1000)
点击不可点击文本("叮叮充电")
wait("扫码充电")
sleep(3000)
toastLog("进入叮叮充电小程序")
点击不可点击文本("福利")
sleep(3000)
wait("活动中心")
sleep(6000)
var target = ["去签到 +5鱼蛋", "去签到 +6鱼蛋", "去签到 +7鱼蛋", "去签到 +8鱼蛋", "去签到 +9鱼蛋", "去签到 +10鱼蛋", "去签到 +30鱼蛋"]
for (var i = 0; i < 7; i++) {
    if (text(target[i]).findOnce()) {
        toastLog("开始签到")
        sleep(2000)
        点击不可点击文本(target[i])
        wait("关闭")
        sleep(35000)
        点击不可点击文本("关闭")
        sleep(2000)
        if (text("继续").findOnce()) {
            sleep(2000)
            点击不可点击文本("继续")
            toastLog("继续观看")
            sleep(12000)
            点击不可点击文本("关闭")
            sleep(1000)
        }
        wait("知道了")
        sleep(2000)
        点击不可点击文本("知道了")
        sleep(5000)
        if (text("暂不开启").findOnce()) {
            sleep(1000)
            点击不可点击文本("暂不开启")
            sleep(1000)
        }
    }
}
while (!text("已领取").findOnce()) {
    点击不可点击文本("去领取")
    wait("关闭")
    sleep(55000)
    点击不可点击文本("关闭")
    sleep(3000)
    if (text("继续").findOnce()) {
        sleep(2000)
        点击不可点击文本("继续")
        toastLog("继续观看")
        sleep(12000)
        点击不可点击文本("关闭")
        sleep(1000)
    }
    wait("休息一下")
    sleep(1000)
    点击不可点击文本("休息一下")
    sleep(3500)
}
//震动1秒
device.vibrate(1000);
toastLog("已观看结束")
home()
sleep(2000)
点击不可点击文本("一键锁屏")
sleep(1000)
launchApp("一键锁屏");


function 点击不可点击文本(str) {
    if(text(str).findOnce()) {
        var strname = text(str).findOnce().bounds()
        click(strname.centerX(), strname.centerY())
    }
    else{
        toastLog("没有找到-->" + str)
    }
}
//等待出现模块
function wait(Name) {
    toastLog("等待-->" + Name)
    text(Name).waitFor()

    sleep(1000)
    toastLog("找到-->" + Name)
}

function 向下滑动() {
    sleep(1500)
    var width = device.width
    var height = device.height
    var suiji = parseInt(Math.random() * 160)
    var end = height / 2 + height / 3
    swipe(width / 2, height / 4, width / 2 - suiji, end, 7000)
    sleep(1000)
}
//悬浮窗
    //=====================================================
    function xuanfu() {
        var window = floaty.window(
            <frame padding="1">
                <vertical  >
                    <horizontal>
                        <button id="action" text="点击" w="35" h="50" style="Widget.AppCompat.Button.Colored" textSize="12sp" />
                        <button id="begin" text="日志" w="35" h="50" textSize="12sp" />
                        <button id="end" text="结束" w="35" h="50" textSize="12sp" />
                        <button id="times" text="计时" w="35" h="50" textSize="12sp" />
                    </horizontal>
    
                    <com.stardust.autojs.core.console.ConsoleView h="150" w="180" id="console" bg="#80000000" />
    
    
                </vertical>
            </frame>
    
        );
    
        window.console.setConsole(runtime.console);
        window.setPosition(0, device.height / 5 * 3);
        // window.console.findViewById(org.autojs.autojs.R.id.input_container).setVisibility(android.view.View.GONE);
        window.console.attr("visibility", "gone");
        
        //开始计时
        var before = new Date();
    
        //日志和结束按钮不显示
        window.begin.setVisibility(8)
        window.end.setVisibility(8)
        window.times.setVisibility(8)
        // window.console.setTouchable(false);
    
        var x = 0, y = 0;
        var windowX, windowY;
        var downTime;
        window.action.setOnTouchListener(function (view, event) {
            switch (event.getAction()) {
                case event.ACTION_DOWN:
                    x = event.getRawX();
                    y = event.getRawY();
                    windowX = window.getX();
                    windowY = window.getY();
                    downTime = new Date().getTime();
                    return true;
                case event.ACTION_MOVE:
                    //移动手指时调整悬浮窗位置
                    window.setPosition(windowX + (event.getRawX() - x),
                        windowY + (event.getRawY() - y));
                    return true;
                case event.ACTION_UP:
                    //手指弹起时如果偏移很小则判断为点击
                    if (Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5) {
                        onClick();
                    }
                    return true;
            }
            return true;
        });
    
        function onClick(str, sec) {
    
            if (window.end.visibility == 8) {
                window.console.setVisibility(0)
                window.end.setVisibility(0)
                window.times.setVisibility(0)
            } else {
                window.console.setVisibility(8)
                window.end.setVisibility(8)
                window.times.setVisibility(8)
            }
        }
    
        var timerId;
    
        function 显示状态信息(str, sec) {
            try {
                clearTimeout(timerId);
            }
            catch (error) {
                toastLog("error");
            }
            ui.run(() => {
                window.action.setText(str);
            });
            timerId = setTimeout(function () {
                ui.run(() => {
                    window.action.setText("");
                });
            }, sec * 1000);
        }
    
    
        window.begin.click(() => {
            window.begin.text() == "显示日志"
            if (window.begin.text() == "显示日志") {
                window.begin.setText("隐藏日志")
                window.console.attr("visibility", "visible");
            } else {
                window.begin.setText("显示日志")
                window.console.attr("visibility", "gone");
            }
        });
    
        window.end.click(() => {
            floaty.closeAll();
            engines.stopAll();
            exit();
        });
        window.times.click(() => {
            var now =new Date();
            var last = Math.floor((now - before) / 1000)
            if(last >= 60) {
                var minutes =  Math.floor(last / 60)
            } else {
                var minutes = 0
            }
            var seconds = last - minutes * 60
            if(minutes > 0 && seconds < 10){
                console.log("运行了：" + minutes + "分 " + "0" + seconds + "秒")
            } 
            if(minutes > 0 && seconds > 10){
                console.log("运行了：" + minutes + "分 "  + seconds + "秒")
            }
            if(minutes <= 0 && seconds < 10){
                console.log("运行了：" + "0" + seconds + "秒")
            } 
            if(minutes <= 0 && seconds > 10){
                console.log("运行了："  + seconds + "秒")
            } 
        });
    
    }
    //悬浮窗结束-----------
 